/** <b>termometer.java</b> - Klasa buduje panel wyswietlajacy wizulane termometry wedlug org.jfree.chart.plot
 * Created on 2010-03-06, 17:45:45 */

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.io.Serializable;
import java.text.DecimalFormat;
import org.jfree.chart.plot.JThermometer;

/** @author MACIEJ KOPLIN - 70482 TIiM, Wydział Elektroniki i Inforamtyki, Politechnika Koszalińska
* III rok, sem VI. Rok akademicki 2009/2010.
* @version termometer 1.0*/

/** <b>termometer.java</b> - Główna klasa komponentu */
public class termometer extends javax.swing.JPanel implements Serializable {
  /** Grid layout 1. */
  private GridLayout gridLayout1 = new GridLayout();
  /** Thermometer 1. */
  private JThermometer thermo1 = new JThermometer();
  /** Thermometer 2. */
  private JThermometer thermo2 = new JThermometer();
  /** Thermometer 3. */
  private JThermometer thermo3 = new JThermometer();
  /** Array of thermometers. */
  private JThermometer[] thermo = new JThermometer[3];

  /** Konstruktor bezparametrowy  */
  public termometer() {
    try {
      jbInit();
    }
    catch (Exception ex) {
      ex.printStackTrace();}
  }

  /**<b>jbInit</b> - ustawia i tworzy odpowiednie termometry oraz dostosowuje ich wartość
  * @exception evt - obsługa wyjątku*/
  void jbInit() throws Exception {
    this.thermo[0] = this.thermo1;
    this.thermo[1] = this.thermo2;
    this.thermo[2] = this.thermo3;

    this.thermo[0].setValue(10.0);
    this.thermo[1].setValue(10.0);
    this.thermo[2].setValue(1000.0);

    this.thermo[0].setOutlinePaint(null);
    this.thermo[1].setOutlinePaint(null);
    this.thermo[2].setOutlinePaint(null);

    this.thermo[0].setShowValueLines(true);
    this.thermo[1].setShowValueLines(true);
    this.thermo[2].setShowValueLines(true);

    this.thermo[0].setForeground(Color.red);
    this.thermo[1].setForeground(Color.blue);
    this.thermo[2].setForeground(Color.black);

    this.thermo[0].setRange(-40, 50);
    this.thermo[1].setRange(1, 99);
    this.thermo[2].setRange(850,1100);

    this.thermo[0].setUnits(0);
    this.thermo[1].setUnits(0);
    this.thermo[2].setUnits(0);

    this.thermo[0].addSubtitle("Temperatura [°C]", new Font("Trebuchet MS", 0, 14));
    this.thermo[1].addSubtitle("Wilgotność [%]", new Font("Trebuchet MS", 0, 14));
    this.thermo[2].addSubtitle("Ciśnienie [hPa]", new Font("Trebuchet MS", 0, 14));
    this.thermo[0].setValueFormat(new DecimalFormat("#0"));
    this.thermo[1].setValueFormat(new DecimalFormat("#0"));
    this.thermo[2].setValueFormat(new DecimalFormat("#0"));

    setLayout(this.gridLayout1);
    add(this.thermo1, BorderLayout.CENTER);
    add(this.thermo2, BorderLayout.CENTER);
    add(this.thermo3, BorderLayout.CENTER);
  }

  /**<b>setValue</b> Metoda / seter
    * @param thermometer - final int thermometer - wybiera termometr
    * @param value -  final double - ustawia wartość termometry
    * @exception Exception ex - w przypadku nie powodzenia  */
  public void setValue(final int thermometer, final double value) {
      try {
          this.thermo[thermometer].setValue(value);
      }
      catch (Exception ex) {
        ex.printStackTrace();}
  }
}
   